package com.csii.modules.online.cgform.handler;

import com.alibaba.fastjson.JSONObject;

import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.csii.core.handler.IFillRuleHandler;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;

public class FillRuleHandler implements IFillRuleHandler {
   public Object execute(JSONObject params, JSONObject formData) {
      String var3 = "CN";
      if (params != null) {
         Object obj = params.get("prefix");
         if (obj != null) {
            var3 = obj.toString();
         }
      }

      SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
      int next = 0;
      try {
         SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
         next = random.nextInt(90) + 10;
      } catch(Exception e) {
         e.printStackTrace();
      }
      //int next = RandomUtils.nextInt(0,90) + 10;
      String newStr = var3 + simpleDateFormat.format(new Date()) + next;
      String name = formData.getString("name");
      if (!StringUtils.isEmpty(name)) {
         newStr = newStr + name;
      }

      return newStr;
   }
}
